<?php

require_once 'inc/common.php';
$data = array();
$name = $db->q1('
	SELECT name
	FROM users
	WHERE fbid = ?
	AND fbid IN (
		SELECT friend_fbid
		FROM friends
		WHERE user_fbid = ?
	)
', $_GET['fbid'], $_SESSION['me']['fbid']);
if ($name) {
	$data['name'] = $name;
	$fblikes = $fb->api("/$_GET[fbid]/likes?limit=5000");
	$categories = array();
	foreach ($fblikes['data'] as $l) {
		$categories[$l['category']] = !empty($categories[$l['category']]) ? $categories[$l['category']] + 1 : 1;
	}
	arsort($categories);
	$data['categories'] = array();
	foreach ($categories as $k => $v) $data['categories'][] = array($k, $v);
}
header('Content-Type: application/json');
echo json_encode($data);

?>